package com.hotelvip.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hotelvip.common.utils.ShiroUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-p配置
 * @author Lzh
 * @date 2020/11/27 11:33
 */
@Component  //将对象交给spring容器管理
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date(); //保证时间一致
        this.setInsertFieldValByName("createdTime", date, metaObject);
        this.setInsertFieldValByName("updatedTime", date, metaObject);
//        this.setInsertFieldValByName("created_user", ShiroUtils.getUsername(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.setUpdateFieldValByName("updatedTime", new Date(), metaObject);

    }
}